package com.spa.interfaces.member;

import cn.dev33.satoken.annotation.SaIgnore;
import com.spa.application.dto.admin.CityDTO;
import com.spa.application.dto.member.MemberIndexCarouselDTO;
import com.spa.application.query.member.LocationQuery;
import com.spa.application.service.admin.CityApplicationService;
import com.spa.domain.service.CarouselService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.enums.dict.base.WhetherTypeEnum;
import com.spa.infrastructure.enums.dict.carousel.CarouselTypeEnum;
import com.spa.infrastructure.mapper.CarouselServiceMapperStruct;
import com.spa.infrastructure.repository.condition.CarouselCondition;
import com.spa.interfaces.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("member/index")
public class MemberIndexController extends BaseController {

    @Resource
    private CarouselService carouselService;

    @Resource
    private CityApplicationService cityApplicationService;

    /**
     * 首页-轮播图
     * @return
     */
    @PostMapping("/carousel")
    @SaIgnore
    public ResponseMessage<List<MemberIndexCarouselDTO>> carousel() {
        CarouselCondition condition = new CarouselCondition();
        condition.setType(CarouselTypeEnum.$0.getCode());
        condition.setIsShow(WhetherTypeEnum.$0.getCode());
       return responseHelper.success(CarouselServiceMapperStruct.INSTANCE.entity2MemberDto4List(carouselService.listAll(condition)));
    }

    /**
     * 技师-获取全部开通城市
     * @return
     */
    @PostMapping("all")
    @SaIgnore
    public ResponseMessage<List<CityDTO>> list() {
        return responseHelper.success(cityApplicationService.findAllCities(10));
    }

    /**
     * 技师-通过经纬度获取对应城市
     * @param query
     * @return
     */
    @PostMapping("getCityByLocation")
    @SaIgnore
    public ResponseMessage<CityDTO> getCityByLocation(@RequestBody LocationQuery query) {
        return responseHelper.success(cityApplicationService.getCityByLocation(query.getLon() + "," + query.getLat()));
    }

}
